package com.hns.can.mainte.web;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.common.domain.GridPage;
import com.hns.can.common.entity.BaseEntity;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.can.common.web.BaseController;
import com.hns.can.mainte.service.EltMhyService;
import com.hns.frame.mybatis.Pagination;
import com.hns.tool.export.ExportUtil;
import com.hns.tool.pub.DateTool;


/**
 * 电机Controller
 * @author:zhangzq
 * @email:
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/eltMhy")
public class EltMhyController extends BaseController{
	
	final private  String[] headerNames = {"车牌号", "营运线路", "所属机构", "采集时间", "总里程", "车速", "型号", "控制器基本状态", 
		"生命(心跳)信号", "转速", "转矩", "档位", "DMC电压", "DMC电流", "控制器温度","电机温度","DMC版本号","逆变器温度","Hybrid Ready状态",
		"电机前端电压","电机后端电压","电机直流电压","电机相电流","电机相电压"};
	final private String[] headerFields = {"licPltNo", "lineName", "organName", "rcrdTime", "totalMile","spdOfMotVhi",
		"eltMhyNo","eltMhyCtrlBasicSt","heartbeatSignal","eltMhyActualRtteSpd","eltMhyActualTorque",
		"gears","eltMhyCtrlBusbarVtg","eltMhyCtrlBusbarEltCrt","eltMhyCtrlTept","eltMhyTept","dmcVrsnNo","ivteTept","hybridReadySt",
		"eltMhyCtrlPreEndVtg","eltMhyCtrlLastEndVtg","eltMhyDcVtg","eltMhyEltCrt","eltMhyVtg"};

	
    @Autowired
    private EltMhyService eltMhyService;
    
    /**
     * 分页查询电机运行分析数据
     * @param params
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/searchEltMhyManagePage")
    @ResponseBody
    public Object searchEltMhyManagePage(CommonParamsVo params) throws Exception {
        Pagination page = eltMhyService.getEltMhyManagePage(params);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
    }
    
    /**
     * 车速转速图表
     * @param params
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/spdAndEMSpdRept")
    @ResponseBody
    public Object spdAndEMSpdRept(CommonParamsVo params) throws Exception{        
        List<BaseEntity> list = eltMhyService.getEltMhyList(params);
        return this.getReturnResult(list);
    }
    
    // DOIT: 2016-12-23 电机-车速转矩图表
    
    /**
     * 车速转矩图表
     * @param params
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/spdAndTorqueRept")
    @ResponseBody
    public Object spdAndTorqueRept(CommonParamsVo params) throws Exception{        
        List<BaseEntity> list = eltMhyService.getEltMhyList(params);
        return this.getReturnResult(list);
    }
    
    // DOIT: 2016-12-23 电机-电压电流图表
    
    /**
     * 电压电流图表
     * @param params
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/vtgAndCrtRept")
    @ResponseBody
    public Object vtgAndCrtRept(CommonParamsVo params) throws Exception{
        List<BaseEntity> list = eltMhyService.getEltMhyList(params);
        return this.getReturnResult(list);
    }
    
    /**
     * 导出电机运行分析数据Excel文件
     * @param params
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("exportEltMhyExcel")
    public void exportEltMhyExcel(CommonParamsVo params,HttpServletResponse response) throws Exception {
        List<BaseEntity> list = eltMhyService.getEltMhyList(params);        
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "excel", "EltMhyRun"+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "电机运行数据");
    }
    
    /**
     * 导出电机运行分析数据Pdf文件
     * @param params
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("exportEltMhyPdf")
    public void exportEltMhyPdf(CommonParamsVo params,HttpServletResponse response) throws Exception {
        List<BaseEntity> list = eltMhyService.getEltMhyList(params);
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "pdf", "EltMhyRun"+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "电机运行数据");
    }

}
